package site.yunnong.atvris.portal.spider.v191;

import com.geccocrawler.gecco.GeccoEngine;
import org.springframework.stereotype.Service;
import site.yunnong.atvris.dao.domain.Video;
import site.yunnong.atvris.dao.mapper.VideoMapper;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author zjh
 * @date 2021/8/29 18:42
 */
@Service
public class V191ImportServiceImpl implements V191ImportService {
    
//    @Scheduled(cron = "30 03 22 29 8 2021")
    public void importVideoSource() {
        String[] urls = new String[16];
        for (int i = 1; i < 17; i++) {
            String url = "https://v.191.cn/index/cate?page=" + i + "&id=0&od=0&keywords=";
            urls[i - 1] = url;
        }
        GeccoEngine.create()
                .classpath("site.yunnong.atvris.portal.spider")
                .seed(urls)
                .thread(1)
                .interval(2000)
                .start();
    }
    
    public static Long SYS_UID = 6L;
    
    public static String SYS_USER_AVATAR = "";
    
    public static String SYS_USER_NICKNAME = "SYSTEM";

    public static Long DEFAULT_PID = 0L;

    public static String DEFAULT_PARTITION_NAME = "";
    
    @Resource
    private VideoMapper videoMapper;
    
    @Override
    public void importSingleVideo(V191Video videoGecco) {
        System.out.println("insert video, video.id: " + videoGecco.getId());
        Video video = Video.builder().uuid(SYS_UID)
                .userAvatar(SYS_USER_AVATAR)
                .userNickname(SYS_USER_NICKNAME)
                .pid(DEFAULT_PID)
                .partitionName(DEFAULT_PARTITION_NAME)
                .level(0)
                .status(1)
                .cover(videoGecco.getImageUrl())
                .videoTime(0L)
                .url(videoGecco.getVideoUrl())
                .seriesNum(1)
                .title(videoGecco.getTitle())
                .rePrintPower(1)
                .fromUrl(videoGecco.getFromUrl())
                .remark(videoGecco.getRemark())
                .uploadTime(LocalDateTime.now())
                .updateTime(LocalDateTime.now())
                .build();
        videoMapper.insertSelective(video);

        System.out.println("insert video, video.id: " + videoGecco.getId() + "SUCCESS");
    }
}
